package com.wufan.day05;

/**
 * @author SongWufan
 * @date 2021/3/8 23:47
 */
public class AnimalTest {
    public static void main(String[] args) {
        Animal animal = new Animal();
        animal.name = "AA";
        animal.setAge(1);
        animal.setLegs(-6);
        animal.show();
    }
}

class Animal{
    String name;
    private int age;
    private int legs;

    /**
     * 对属性的获取
     * @return
     */
    public int getLegs() {
        return this.legs;
    }

    /**
     * 对属性的设置
     * @param legs
     */
    public void setLegs(int legs) {
        if (legs >= 0 && legs % 2 == 0) {
            this.legs = legs;
        }
        else {
            this.legs = -1;
        }
    }
    public void animalEat() {
        System.out.println("动物进食");
    }

    public void show() {
        System.out.println("Animal{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", legs=" + legs +
                '}');
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
